package com.fenghuajueli.module_user.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.View;

import androidx.viewpager.widget.ViewPager;

import com.blankj.utilcode.util.ConvertUtils;

import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView;

/**
 * ===========================================================
 * author：songpeng on 12/7/20 16:49
 * email：fenghuajueli@gmail.com
 * ===========================================================
 * 我的页面tab适配器
 */
public class MineTabAdapter extends CommonNavigatorAdapter {
    private ViewPager viewPager;

    private String[] tabList = new String[]{"收藏", "草稿"};
//    private String[] tabList = new String[]{"草稿"};

    public MineTabAdapter(ViewPager viewPager) {
        this.viewPager = viewPager;
    }

    @Override
    public int getCount() {
        return tabList.length;
    }

    @Override
    public IPagerTitleView getTitleView(Context context, int index) {
        ColorTransitionPagerTitleView colorTransitionPagerTitleView = new ColorTransitionPagerTitleView(context);
        colorTransitionPagerTitleView.setNormalColor(Color.parseColor("#AAADB4"));
        colorTransitionPagerTitleView.setSelectedColor(Color.WHITE);
        colorTransitionPagerTitleView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        colorTransitionPagerTitleView.setText(tabList[index]);
        colorTransitionPagerTitleView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                viewPager.setCurrentItem(index, false);
            }
        });
        return colorTransitionPagerTitleView;
    }

    @Override
    public IPagerIndicator getIndicator(Context context) {
        LinePagerIndicator indicator = new LinePagerIndicator(context);
        indicator.setMode(LinePagerIndicator.MODE_WRAP_CONTENT);
        indicator.setRoundRadius(10);
        indicator.setColors(Color.WHITE);
        indicator.setLineHeight(ConvertUtils.dp2px(4));
        return indicator;
    }
}
